<?php
/**
 * 单页
 * Created by PhpStorm.
 * User: Yui
 * Date: 2017/5/18 0018
 * Time: 14:24
 */

namespace backend\controllers;

use Yii;
use common\library\comFun;
use common\controllers\BackendCommonCtrl;
use common\services\SinglePageSve;
use yii\helpers\Url;

class SinglePageController extends BackendCommonCtrl
{
    /**
     * 列表
     */
    public function actionList()
    {
        $SinglePageSve = new SinglePageSve();
        $rs = $SinglePageSve->getList();
        return $this->render('list', $rs['data']);
    }

    /**
     * 修改
     */
    public function actionEdit()
    {
        $request = Yii::$app->request;
        $SinglePageSve = new SinglePageSve();
        if ($request->isPost) {
            $rs = $SinglePageSve->update($request->post());
            if ($rs['code'] === 0) {
                $rs['redirect'] = Url::toRoute('/single-page/list');
            }
            return $this->asJson($rs);
        } else {
            $id = $request->get('single_page_id');
            $data = [];
            //检查id
            if (comFun::isPositiveInt($id)) {
                $rs = $SinglePageSve->getInfo(['single_page_id' => $id]);

            }
            return $this->render('edit', ['info' => $rs]);
        }
    }

}